package nl.unimaas.group11.project1_3.graphics;

import java.awt.Button;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.Label;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.ButtonGroup;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.border.Border;
import javax.swing.border.EtchedBorder;
import javax.swing.border.TitledBorder;

import nl.unimaas.group11.project1_3.Listener.Listener;

public class LeftPane extends JPanel {
	private static final long serialVersionUID = 1L;

	public Button startButton, aboutButton, exitButton;
	public JTextField valueA, valueB, valueC, secs;
	public JRadioButton pentosRB, boxesBruteforceRB, greedyRB;
	public JLabel test;


	public LeftPane() {
		setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
		setPreferredSize(new Dimension(200, 600));
		setBackground(Render.MEDIUM_GREY_COLOR);
		
		setForeground(Color.black);
		this.validate();
	
		

		JPanel logoPanel = new JPanel();
		logoPanel.setBackground(Render.MEDIUM_GREY_COLOR);

		BufferedImage myPicture;
		try {
			myPicture = ImageIO.read(new File("res/images/logo2.gif"));
			JLabel picLabel = new JLabel(new ImageIcon(myPicture), SwingConstants.LEFT);

			logoPanel.add(picLabel);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		add(logoPanel);

		JPanel algoChoice = new JPanel();
		algoChoice.setLayout(new GridLayout(6, 1));
		algoChoice.setBackground(Render.MEDIUM_GREY_COLOR);
		algoChoice.setForeground(Color.black);
		algoChoice.setBorder(new TitledBorder(new EtchedBorder(), "Algorithm choice", TitledBorder.CENTER, TitledBorder.DEFAULT_POSITION));

		pentosRB = new JRadioButton("Pentos");
		boxesBruteforceRB = new JRadioButton("Boxes Bruteforce");
		greedyRB = new JRadioButton("Boxes Greedy");

		ButtonGroup algoButtonGroup = new ButtonGroup();
		pentosRB.setBackground(Render.MEDIUM_GREY_COLOR);
		algoButtonGroup.add(pentosRB);
		boxesBruteforceRB.setBackground(Render.MEDIUM_GREY_COLOR);
		algoButtonGroup.add(boxesBruteforceRB);
		greedyRB.setBackground(Render.MEDIUM_GREY_COLOR);
		algoButtonGroup.add(greedyRB);
		pentosRB.setSelected(true);

		algoChoice.add(pentosRB);
		algoChoice.add(boxesBruteforceRB);
		algoChoice.add(greedyRB);
		algoChoice.add(new Label(""));
		algoChoice.add(new Label("Seconds to run Bruteforce:", Label.CENTER));

		secs = new JTextField("3");
		decorateTextField(secs);

		algoChoice.add(secs);

		add(algoChoice);

		JPanel boxesValuesPanel = new JPanel();
		boxesValuesPanel.setLayout(new GridLayout(2, 3));
		boxesValuesPanel.setBackground(Render.MEDIUM_GREY_COLOR);
		boxesValuesPanel.setForeground(Color.black);
		boxesValuesPanel.setBorder(new TitledBorder(new EtchedBorder(), "Value of Boxes", TitledBorder.CENTER, TitledBorder.DEFAULT_POSITION));

		valueA = new JTextField("3");
		decorateTextField(valueA);
		valueB = new JTextField("4");
		decorateTextField(valueB);
		valueC = new JTextField("5");
		decorateTextField(valueC);

		boxesValuesPanel.add(new Label("Box A", Label.CENTER));
		boxesValuesPanel.add(new Label("Box B", Label.CENTER));
		boxesValuesPanel.add(new Label("Box C", Label.CENTER));
		boxesValuesPanel.add(valueA);
		boxesValuesPanel.add(valueB);
		boxesValuesPanel.add(valueC);

		add(boxesValuesPanel);

		startButton = new Button("Start");
		startButton.addActionListener(new Listener());
		add(decorateButton(startButton));

		JPanel aboutAndExitButtons = new JPanel();
		aboutAndExitButtons.setLayout(new GridLayout(1, 2));

		aboutButton = new Button("About");
		aboutButton.addActionListener(new Listener());
		aboutAndExitButtons.add(decorateButton(aboutButton));

		exitButton = new Button("Exit");
		exitButton.addActionListener(new Listener());
		aboutAndExitButtons.add(decorateButton(exitButton));

		add(aboutAndExitButtons);

	}

	
	

	private void decorateTextField(JTextField a) {
		a.setBackground(Render.LIGHT_GREY_COLOR);
		a.setCaretColor(Color.BLACK);
		a.setForeground(Color.BLACK);
		Border border = BorderFactory.createLineBorder(Color.BLACK);
		a.setBorder(border);
		a.setHorizontalAlignment(JTextField.CENTER);
	}

	private Button decorateButton(Button b) {
		b.setBackground(Render.LIGHT_GREY_COLOR);
		b.setForeground(Color.BLACK);
		return b;
	}

}